<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	//显示统计数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$order['all']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6)));
	$order['day']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6),'createtime >'=>$daytime));
	$money['all']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1),'price');
	$money['day']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ispay'=>1,'createtime >'=>$daytime),'price');
	
	$order['table']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>1));
	$order['out']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>2));
	$order['self']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>3));
	$order['yuyue']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>4));
	
	$money['table']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>1));
	$money['out']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>2));
	$money['self']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>3));
	$money['yuyue']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3,'buytype'=>4));
		
	$member['day'] = pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime));
	$member['all'] = pdo_count('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid']));
	$access['day'] = pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop','createtime >'=>$daytime));
	$access['all'] = pdo_count('core_access_log',array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_weishop'));
	//月份
	for($i=0;$i<12;$i++){
			if($i==0){
				$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
				$yueend = time();
				
			}else{
				$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
				$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
			}
			$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>array(1,2,3,5,6));
			$params['createtime between']=array($yuestart,$yueend);
			$month12[] = date('Y-m',strtotime('-'.$i.' month'));
			//$monthaccess[]=pdo_count('core_access_log',$params);
			$monthorder[]=pdo_count('jy_weishop_order',$params);
			$monthfee=pdo_getsum('jy_weishop_order',$params,'price');
			$monthmoney[]=intval($monthfee);
			//$monthcredit2[]=pdo_getsum('core_members',$params,'credit2');
	}
	$monthorder=array_reverse($monthorder);
	$monthmoney=array_reverse($monthmoney);
	$month12=array_reverse($month12);
	$htmls=array(
		array('type'=>'data','num'=>12,'one_num'=>3,'title'=>'今日数据/总数据','datas'=>array(
			array('title'=>'总订单数(成功的)','num'=>2,'data'=>array($order['day'],$order['all'])),
			array('title'=>'订单金额(支付的)','yuan'=>1,'num'=>2,'data'=>array($money['day'],$money['all'])),
			array('title'=>'访客统计','num'=>2,'data'=>array($access['day'],$access['all'])),
			array('title'=>'总用户','num'=>2,'data'=>array($member['day'],$member['all'])),
		)),
		array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'月度成交金额','datas'=>array(
					'datas'=>array(
						array('name'=>'成交订单数','value'=>$monthorder),
						array('name'=>'成交订单金额','value'=>$monthmoney),
					),
					'xdatas'=>$month12,
		)),
	);
	$return['htmls']=$htmls;
	if($_SESSION['isfounder'] && !$_SESSION['isonesyssite']){
		//月份
		$month12=array();
		for($i=0;$i<12;$i++){
			if($i==0){
				$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
				$yueend = time();
				
			}else{
				$yuestart = mktime(0,0,0,date('m')-$i,1,date('Y'));
				$yueend = mktime(0,0,0,date('m')-$i+1,1,date('Y'));
			}
			$params=array();
			$params['createtime between']=array($yuestart,$yueend);
			$month12[] = date('Y-m',strtotime('-'.$i.' month'));
			//$monthaccess[]=pdo_count('core_access_log',$params);
			$allaccess[]=pdo_count('core_access_log',$params);
			$useraccess[]=pdo_count('core_members',$params);
			$params['status']=1;
			$kehufee[]=pdo_getsum('core_paylog',$params,'fee')?:0;
			$sysfee[]=pdo_getsum('core_account_pay_log',$params,'fee')?:0;
		}
		$allaccess=array_reverse($allaccess);
		$useraccess=array_reverse($useraccess);
		$kehufee=array_reverse($kehufee);
		$sysfee=array_reverse($sysfee);
		$month12=array_reverse($month12);
		$access['site_day']=pdo_count('core_users',array('createtime >'=>$daytime));
		$access['site_all']=pdo_count('core_users',array());
		$access['member_day']=pdo_count('core_members',array('createtime >'=>$daytime));
		$access['member_all']=pdo_count('core_members',array());
		$access['pay_day']=pdo_getsum('core_paylog',array('status'=>1,'createtime >'=>$daytime),'fee');
		$access['pay_all']=pdo_getsum('core_paylog',array('status'=>1),'fee');
		$ads = cache_read('cloud_ads');	
		if(!$ads){
			$ads=cloud_request('release.get_data.sitead',$params,'','',3);
			cache_write('cloud_ads',$ads);
		}
		$ads=json_decode($ads,true);
		if($ads['hd_topimg']){
			$adshow=true;
		}
		$return['item']['ad_img']=$ads['hd_topimg'];
		$htmls=array(
			array('type'=>'ad_img','name'=>'ad_img','url'=>$ads['huodonglink'],'adshow'=>$adshow,'width'=>'100%','height'=>'80px'),
			array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'访问/流水数据指标_Access data','datas'=>array(
					'datas'=>array(
						array('name'=>'访问次数','value'=>$allaccess),
						array('name'=>'客户流水','value'=>$kehufee),
						array('name'=>'平台流水','value'=>$sysfee),
						array('name'=>'新增会员','value'=>$useraccess),
					),
					'xdatas'=>$month12,
			)),
			array('type'=>'data','tpltype'=>4,'one_num'=>3,'title'=>'店铺今日/总数据指标','datas'=>array(
					array('title'=>'店铺数量','num'=>2,'data'=>array($access['site_day'],$access['site_all'])),
					array('title'=>'消费者数量','bgcolor'=>'#009933','num'=>2,'data'=>array($access['member_day'],$access['member_all'])),
					array('title'=>'流水金额','bgcolor'=>'#3366FF','num'=>2,'data'=>array($access['pay_day'],$access['pay_all'])),
			)),
		);
		$return['htmls']=$htmls;
	}
	exi($return);
}